import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        isShowLoading: false, // 全局 loading
        // 左侧菜单栏数据
        menuItems: [
            {
                name: 'home', // 要跳转的路由名称 不是路径
                size: 18, // icon大小
                type: 'md-analytics', // icon类型
                text: '数据', // 文本内容
            },
            {
                name: 'server', // 要跳转的路由名称 不是路径
                size: 18, // icon大小
                type: 'md-filing', // icon类型
                text: '服务', // 文本内容
            },
        ],
        cardInfo: [
            {
                id: 1,
                tag: 'card',
                imgUrl: 'https://dev-file.iviewui.com/stJXDnKhL5qEBD0dHSDDTKbdnptK6mV5/large',
                title: '标题',
            },
            {
                id: 2,
                tag: 'card',
                imgUrl: 'https://dev-file.iviewui.com/stJXDnKhL5qEBD0dHSDDTKbdnptK6mV5/large',
                title: '标题',
            },
            {
                id: 4,
                tag: 'card',
                imgUrl: 'https://dev-file.iviewui.com/stJXDnKhL5qEBD0dHSDDTKbdnptK6mV5/large',
                title: '标题',
            },
            {
                id: 3,
                tag: 'card',
                imgUrl: 'https://dev-file.iviewui.com/stJXDnKhL5qEBD0dHSDDTKbdnptK6mV5/large',
                title: '标题',
            },
        ],
        ActiveCardNum: 0,
    },
    mutations: {
        setMenus(state, items) {
            state.menuItems = [...items]
        },
        setLoading(state, isShowLoading) {
            state.isShowLoading = isShowLoading
        },
        SETACTIVENUM(state, item) {
            state.ActiveCardNum = item
        },
        DELETECARDINFO(state, id) {
            let index = state.cardInfo.findIndex((item) => item.id == id)
            state.cardInfo.splice(index, 1)
        },
    },
})

export default store